package com.github.jspxnet.worktask.core.job;

import com.github.jspxnet.txweb.table.Member;
import com.github.jspxnet.utils.StringUtil;
import com.github.jspxnet.worktask.model.enums.FlowNodeEnumType;
import com.github.jspxnet.worktask.model.enums.WorkTaskEnumType;
import com.github.jspxnet.worktask.table.WorkTask;
import com.github.jspxnet.worktask.util.WorkFlowUtil;
import java.util.List;

/**
 * 会签,配置的所有人员都审核通过后才走到下一个节点
 * 如果被驳回,就流程全部驳回结束流程
 */
public class AndJobTask extends BaseTaskAction{
    @Override
    public boolean execute() throws Exception {
        //会签
        currentWorkTask.setUsers(workTaskParam.getUsers());
        currentWorkTask.setWorkTaskType(WorkTaskEnumType.AUDIT.getValue());
        currentWorkTask.setFlowNodeType(FlowNodeEnumType.END.getValue());
        runtimeServiceDAO.update(currentWorkTask,new String[]{"flowNodeType","workTaskType","users"});

        //有人通过
        WorkTask workTaskQuery = runtimeServiceDAO.getWorkTask(currentConfFlowNode.getFlowNo(),currentConfFlowNode.getNamespace(),workTaskParam.getDocumentNo(),currentConfFlowNode.getNodeId());
        List<Member> userList = userAdapterDAO.getMemberForExpression(currentConfFlowNode.getUsers());
        int auditCount = WorkFlowUtil.getAuditCount(workTaskQuery.getUserFlowLogList());
        return StringUtil.isNull(currentConfFlowNode.getUsers()) || userList.size() == auditCount;
    }
}
